<?php

class Application_Model_DbTable_Language extends Zend_Db_Table_Abstract
{

    protected $_name = 'ojlanguage';

    public function addLanguage(Application_Model_Language $language){
        $data = array(
            'ojlName' => $language->getName(),
            'ojlCompiler' => $language->getCompiler(),
            'ojlCompilerPath' => $language->getCompilerPath(),
            'ojlCompileArgs' => $language->getCompileArgs(),
            'ojlMemo' => $language->getMemo()
        );
        $this->insert($data);
    }
    
    public function updateLanguage(Application_Model_Language $language){
        $data = array(
            'ojlName' => $language->getName(),
            'ojlCompiler' => $language->getCompiler(),
            'ojlCompilerPath' => $language->getCompilerPath(),
            'ojlCompileArgs' => $language->getCompileArgs(),
            'ojlMemo' => $language->getMemo()
        );
        $this->update($data, 'ojlId = '.$language->getId());
    }
    
    public function deleteLanguage(int $id){
        $this->delete('ojlId = '.$id);
    }
    
    public function getLanguageById($id){
        $row = $this->fetchRow('ojlId = '.$id);
        if(!$row)
            return null;
//        return new Application_Model_Language(
//                $id,$row->ojlName,$row->ojlCompiler,$row->ojlCompilerPath,
//                $row->CompileArgs, $row->ojlMemo);
        
        $language = new Application_Model_Language();
        $language->setId($id);
        $language->setName($row->ojlName);
        $language->setCompiler($row->ojlCompiler);
        $language->setCompilerPath($row->ojlCompilerPath);
        $language->setCompileArgs($row->ojlCompileArgs);
        $language->setMemo($row->ojlMemo);
        
        return $language;
    }
    
    public function getAllLanguages(){
        $rowset = $this->fetchAll();
        $languages = array();
        foreach ($rowset as $row) {
//            $language = new Application_Model_Language(
//                $id,$row->ojlName,$row->ojlCompiler,$row->ojlCompilerPath,
//                $row->CompileArgs, $row->ojlMemo);
            $language = new Application_Model_Language();
            $language->setId($row->ojlId);
            $language->setName($row->ojlName);
            $language->setCompiler($row->ojlCompiler);
            $language->setCompilerPath($row->ojlCompilerPath);
            $language->setCompileArgs($row->ojlCompileArgs);
            $language->setMemo($row->ojlMemo);
            
            $languages[] = $language;
        }
        return $languages;
    }

}

